#!/bin/sh

cp benchprog/Output/$1.bc .
echo "opt: mem2reg ..."
opt -mem2reg -indvars -loopsimplify $1.bc -f -o $1.mem2reg.bc
echo "opt: phase1 ..."
opt -load $LLVMDIR/lib/libLLVMCS6241_part3.so -phase1 $1.mem2reg.bc -f -o $1.instr_checks.bc

echo "llvm-gcc ... llvm-link ..."
llvm-gcc ../../check.c  -O3 -emit-llvm -c -o check.bc
llvm-ld  check.bc $1.instr_checks.bc  -o $1.checked

opt -O3 $1.checked.bc > $1.O3checked.bc
cp $1.O3checked.bc $1.overhead.bc
llc -f $1.O3checked.bc
gcc -O3 -lm $1.O3checked.s

mv a.out $1.checked.exe

opt -O3 $1.bc > $1.O3.bc
llc -f $1.O3.bc
gcc -O3 -lm $1.O3.s
mv a.out $1.exe

./runbench.sh $1
./runbench.sh $1
./runbench.sh $1

#lli $1_check.bc
